/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.market.web.EJB;

import com.market.web.model.Customer;
import com.market.web.model.Tempshoppingcart;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author ps
 */
@Stateless
public class TempshoppingcartFacade extends AbstractFacade<Tempshoppingcart> {
    @PersistenceContext(unitName = "onlineMarketPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }
    
    
    
    
    public List<Tempshoppingcart> getTempSCByCID(Customer c) {
        Query createNamedQuery = getEntityManager().createNamedQuery("Tempshoppingcart.findByCustID");

        createNamedQuery.setParameter("custID", c.getCustId());
        
        if (createNamedQuery.getResultList().size() > 0) {
            List<Tempshoppingcart> lst = createNamedQuery.getResultList();
            
            return lst;
        }
        else {
            return null;
        }
    }

       public void removeTempSCByCID(Customer c) {
           
            List<Tempshoppingcart> toDelete = getTempSCByCID(c);
            
            
            for(int i =0; i < toDelete.size();i++)
            {
                
                Tempshoppingcart t = toDelete.get(i);
                em.remove(t);
                
                
            }
            
        }

    public TempshoppingcartFacade() {
        super(Tempshoppingcart.class);
    }
    
}
